<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <base href="#(basePath)"/>
    <title>清算管理 - 流水列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=1">
    <link rel="stylesheet" href="static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="static/admin.css" media="all">
    <style type="text/css">.layui-elem-quote span{margin:0 6px;}</style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">收款卡</label>
                    <div class="layui-input-inline">
                        <select id="youliaccount" name="youliaccount">
                            <option value="">请选择</option>
                            #for(item : youliAccountList)
                            <option value="#(item.accountNo)">#(item.accountNo)-#(item.accountName)</option>
                            #end
                        </select>
                    </div>
                </div>


                <div class="layui-inline">
                    <label class="layui-form-label">用户编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="merchCode" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="createTimeStart" name="createTimeStart" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="createTimeEnd" name="createTimeEnd" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-web-list-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>

                    #auth()
                    <button link="admin/clearing/youliaccount/export" class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="exportExcel">导出收款卡流水</button>
                    #end
                </div>
            </div>
        </div>


    <div class="layui-card-body">
        <table id="LAY-web-list" lay-filter="LAY-web-list"></table>
        <script type="text/html" id="table-content-list">
            #auth()
            <a link="admin/order/view" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>
            #end
            #[[ {{#  if(d.orderStatus == 'TS'){ }} ]]#
            #auth()
            <a link="admin/order/certificate" class="layui-btn layui-btn-xs" lay-event="certificate"><i class="layui-icon layui-icon-auz"></i>回执</a>
            #end
            #[[ {{#  } }} ]]#
        </script>
    </div>
    </div>
</div>

<script src="static/layui/layui.js"></script>
<script>
    layui.config({
        base: '#(basePath)' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'laydate', 'table', 'youliorder'], function(){
        var laydate = layui.laydate;
        //日期时间选择器
        laydate.render({
            elem: '#createTimeStart'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#createTimeEnd'
            ,type: 'datetime'
        });

        // 表格
        var $ = layui.$, table = layui.table, form = layui.form;

        //监听搜索
        form.on('submit(LAY-web-list-search)', function(data){
            table.reload('LAY-web-list', {
                where: data.field,
                page: {curr: 1}
            });
        });

        //判断字符是否为空的方法
        function isEmpty(obj){
            if(typeof obj == "undefined" || obj == null || obj == ""){
                return true;
            }else{
                return false;
            }
        }

        form.on('submit(exportExcel)', function(data){
            var field = data.field;
            var createTimeStart = $("#createTimeStart").val();
            var createTimeEnd = $("#createTimeEnd").val();
            var youliaccount = $("#youliaccount").val();
            if(isEmpty(createTimeStart) || isEmpty(createTimeEnd)){
                layer.alert("导出Excel必须选择开始时间和结束时间，并且时间段建议不超过3个月!");
                return;
            }
            // if(isEmpty(youliaccount)){
            //     layer.alert("导出Excel必须选择友利账户");
            //     return;
            // }
            layer.msg("正在导出Excel表...");
            $.ajax({
                type:"POST",
                url:"admin/clearing/youliaccount/report",
                data:field,
                dataType: "JSON",
                success: function(data) {
                    //alert(JSON.stringify(data));
                    if(data.code==0){
                        window.location.href= data.msg;
                    }else {
                        alert(JSON.stringify(data));
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("网络错误");
                }

            });
            //执行重载
            table.reload('LAY-web-list', {
                where: field,
                page: {curr: 1}
            });
        });

    });
</script>
</body>
</html>
